package com.kylefu.design.pattern;

/**
 * 工厂模式
 */
public class FactoryMethod {

  public Color getBean(String name){
    if("Blue".equals(name)){
      return new Blue();
    }else if("Red".equals(name)){
      return new Red();
    }
    throw new RuntimeException("Not Support Name");
  }

  public abstract class Color{
    public abstract String getColor();
  }

  public class Blue extends Color{
    @Override
    public String getColor() {
      return "#123";
    }
  }

  public class Red extends Color{
    @Override
    public String getColor() {
      return "#456";
    }
  }
}
